/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package cn.itcast;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>Project: JavaStudy - Work3
 * <p>Powered by jiangbo On 2023-01-12
 * 14:45:47
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class Work3 {
    public static Map<String, List<String>> map=new HashMap<>();
    public static void main(String[] args) {

        File file = new File("C:\\Users\\30444\\Desktop\\作业");

        count(file);
        map.forEach((k, v)->System.out.printf("%s %d %n",k,v.size()));
    }
    public static void count(String dir){
        count(new File(dir));
    }
    public static void count(File dir){
        if (dir.isDirectory()){
            for (File t:dir.listFiles()){
                if (t.isDirectory()){
                    count(t);
                }else {
                    String fn=t.getName();
                    String ext=fn.lastIndexOf(".")==-1?"Unknow":fn.substring(fn.lastIndexOf(".")+1);
                    if (map.containsKey(ext)){
                        List<String> list=map.get(ext);
                        list.add(t.getAbsolutePath());
                        map.put(ext,list);

                    }else {
                        List<String> list=new ArrayList<String>();
                        list.add(t.getAbsolutePath());
                        map.put(ext,list);
                    }
                }
            }
        }
    }
}


